<template>
    <div class="basic-layout">
        <div :class="['nav-side',isFold?'fold':'unfold']">
            <div class="logo">
                <img src="../assets/logo.png" alt="">
                <span>Manager</span>
            </div>
             <el-menu
                default-active="2"
                class="el-menu-vertical-demo"
                background-color="#001529"
                text-color="#fff"
                router
                >
                <!-- 渲染请求回来的菜单
                请求回来的菜单分为一级二级（递归调用这个组件渲染二级菜单） -->
                <treeMenu :userMenu="userMenu"/>
             </el-menu>
        </div>
        <div :class="['content-right',isFold?'fold':'unfold']">
            <div class="nav-top">
                <div class="nav-left">
                    <div class="menu-flod" @click="toggle">
                    <el-icon><Fold/></el-icon>   
                </div>
               <div class="bread">
                <bread-crumb>
                <div></div>
                </bread-crumb>
               </div>
                </div>
                <div>
<el-dropdown @command="handleLogout"> 
    <span class="el-dropdown-link">
     {{userInfo.userName}}
      <el-icon class="el-icon--right">
        <arrow-down />
      </el-icon>
    </span>
    <template #dropdown>
      <el-dropdown-menu >
        <el-dropdown-item command="email">邮箱：{{userInfo.userEmail}}</el-dropdown-item>
        <el-dropdown-item command="logout">退出</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
                </div>
            </div>
            <div class="wrapper">
                <router-view></router-view>
            </div>
        </div>      
    </div>
</template>
<script setup>
import api from './../api'
import TreeMenu from './../components/TreeMenu.vue'
import BreadCrumb from './../components/BreadCrumb.vue'
import {useStore}from "vuex"
import {useRouter}from "vue-router"
import{ref}from'vue'
const router=useRouter()
const store=useStore()
let userMenu=ref([])
let isFold=ref(false)
const getPermissionList=async()=>{
   let{actionList,menuList}=await api.getPermissonList()
   userMenu.value=menuList 
}
getPermissionList()
const toggle=()=>{
isFold.value=!isFold.value
}
let userInfo = store.state.userInfo
const handleLogout = (key) => {
  console.log(key);
  if (key == "email") return;
  // 如果点击是退出
  // 1.清除缓存
  store.commit("saveUserInfo", "");
  userInfo = {};
  // 2.回到登录页
  router.push("/login");
};
</script>
<style lang="scss">
.basic-layout {
  position: relative;
  .nav-side {
    position: fixed;
    width: 200px;
    height: 100vh;
    background-color: #001529;
    color: #fff;
    overflow-y: auto;
    transition: width 0.5s;
    .logo {
      display: flex;
      align-items: center;
      font-size: 18px;
      height: 50px;
      img {
        margin: 0 16px;
        width: 32px;
        height: 32px;
      }
    }
    .nav-menu {
      height: calc(100vh - 50px);
      border-right: none;
    }
    // 合并
    &.fold {
      width: 64px;
    }
    // 展开
    &.unfold {
      width: 200px;
    }
  }
  .content-right {
    margin-left: 200px;
    // 合并
    &.fold {
      margin-left: 64px;
    }
    // 展开
    &.unfold {
      margin-left: 200px;
    }
    .nav-top {
      height: 50px;
      line-height: 50px;
      display: flex;
      justify-content: space-between;
      border-bottom: 1px solid #ddd;
      padding: 0 20px;
      .nav-left {
        display: flex;
        align-items: center;
        .menu-fold {
          margin-right: 15px;
          font-size: 18px;
        }
      }
      .user-info {
        .notice {
          line-height: 30px;
          margin-right: 15px;
          cursor: pointer;
        }
        .user-link {
          cursor: pointer;
          color: #409eff;
        }
      }
    }
    .wrapper {
      background: #eef0f3;
      padding: 20px;
      height: calc(100vh - 50px);
      .main-page {
        background: #fff;
        height: 100%;
      }
    }
  }
}
</style>
